/**
 * 创建时间：2009-12-15
 * 创建人：朱家进
 * 内容：修改操盘类型
 * 
 */
package com.zjht.gmcc.servlet.sys;

import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.BaseServlet;
import com.zjht.gmcc.bean.util.InitParam;
import com.zjht.gmcc.bean.util.MyJDBC;

public class ChangeCSType extends BaseServlet {

	private static final long serialVersionUID = 1L;

	public boolean process(HttpServletRequest request, HttpServletResponse response, HttpSession session, PrintWriter out, MyJDBC myJDBC, String menu)
			throws Exception {

		int flag = 0;
		String act = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String orgaCode = request.getParameter("orgaCode");
		String orgaName = request.getParameter("orgaName");
		int areaid = 0;

		String sql = "SELECT areaid FROM ORGANIZA WHERE OrgaCode= ? ";
		ps = myJDBC.prepareStatement(sql);
		ps.setString(1, orgaCode);
		rs = ps.executeQuery();
		if (rs.next()) {
			areaid = rs.getInt("areaid");
			flag = 1;
		}
		rs.close();
		rs = null;

		if (flag == 1) {
			sql = "UPDATE area SET etype = ? WHERE areaid = ?";
			ps = myJDBC.prepareStatement(sql);
			ps.setString(1, "1");
			ps.setInt(2, areaid);
			flag = ps.executeUpdate();
		}
		act = orgaName + " 转换操盘类型";
		if (flag == 1) {
			InitParam.initOrgaInfo();
			alertOK(out, act + "成功！", "dialogArguments.location.href='orga/orga.jsp?orgacode=" + orgaCode + "&orgaType=2';window.returnValue='"
					+ orgaCode + "';window.close();");
		} else {
			errAlert(request, out, menu, act + "失败");
		}
		return flag == 1;
	}
}
